package com.jeecms.edu.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.jeecms.common.web.ResponseUtils;
import com.jeecms.edu.entity.SchoolInformation;

/**
 * database页面的热门学校及集团
 */
@WebServlet("/ShowHotSchool")
public class ShowHotSchool extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		List locallist=SchoolInformation.localHotSchoolList();
		List globallist=SchoolInformation.globalHotSchoolList();
		JSONObject jsonObject=new JSONObject();
		
		//热门学校
		String localresult="";		//热门学校集合
		int localsize=locallist.size();	
		if (locallist.size()>7) {   //增加显示数量限制
			localsize=7;
		}
		for (int i = 0; i < localsize; i++) {
			Map map=(Map) locallist.get(i);
			String school=(String) map.get("schoolname");
			String changes="javascript:gotoDetail('"+school+"');";
			localresult+="<div class='hot_thread1'><a href="+changes+"><img src='"+map.get("schoolimgurl")+"' class='hot_pic' /></a>"
						+"<p><a href="+changes+">"+map.get("schoolname")+"</a></p><p>"+map.get("region")+"  "+map.get("schoolnature")+"</p></div>";
		}
		jsonObject.put("localhotschool", localresult);
		
		//热门国际教育集团
		
		//国际热门学校
		String globalresult="";		 //国际热门学校集合
		int globalsize=globallist.size();	
		if (globallist.size()>3) {   //增加显示数量限制
			globalsize=3;
		}
		for (int i = 0; i < globalsize; i++) {
			Map map=(Map) globallist.get(i);
			String school=(String) map.get("schoolname");
			String changes="javascript:gotoDetail('"+school+"');";
			globalresult+="<div class='hot_thread1'><a href="+changes+"><img src='"+map.get("schoolimgurl")+"' class='hot_pic' /></a>"
						+"<p><a href="+changes+">"+map.get("schoolname")+"</a></p><p>"+map.get("region")+"  "+map.get("schoolnature")+"</p></div>";
		}
		jsonObject.put("globalhotschool", globalresult);
		
		String json = jsonObject.toJSONString();
		ResponseUtils.renderJson(response, json); 
		
		/*<div class="hotgroup"><p><a href="">教育集团名称：宝钢集团</br>下属学校/下属学校/下属学校/下属学校、下属学校/下属学校/下属学校</a></p></div>*/
	}
}
